<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Character encoding</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch08.html" title="Chapter 8. Text and font handling"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Character encoding</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 8. Text and font handling</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Character encoding"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec1.character-encoding"></a>Character encoding</h2></div></div></div>
            
            <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
                    <p>If you are not using Japanese, Chinese, Cyrillic , Greek or Hebrew
                        languages then this section can be safely skipped.</p>
                </div><p>The core problem for the library is that it has no way of knowing in what
                input encoding the string given to the library is using. Hence it is necessary to,
                sometime, tell the library what input encoding is being used in order for the
                library to do necessary character encoding conversion to generate UTF-8 (or UTF-16)
                as needed to properly render the TTF fonts. The specific encoding options for each
                major supported locale are explained below.</p>
            <p>By default all JpGraph library files and examples are encoded in UTF-8</p>
            <p>All defines mentioned below can be found in the file
                    "<code class="filename">jpgraph_ttf.inc.php</code>" </p>
            <div class="sect2" title="Japanese encoding options"><div class="titlepage"><div><div><h3 class="title"><a name="id2500277"></a>Japanese encoding options</h3></div></div></div>
                
                <p>There is only one possible option that can be specified.</p>
                <p>
                    </p><div class="table"><a name="id2500290"></a><p class="title"><b>Table 8.4. Japanese encoding options</b></p><div class="table-contents">
                        
                        <table summary="Japanese encoding options" border="1"><colgroup><col class="c1"><col class="c2"><col class="c3"></colgroup><thead><tr><th>Symbolic define</th><th>Possible values </th><th>Description</th></tr></thead><tbody><tr><td><code class="code">ASSUME_EUCJP_ENCODING</code></td><td>true/false</td><td>Assumes that Japanese text have been entered in EUC-JP
                                        encoding. If this define is true then conversion from EUC-JP
                                        to UTF8 is done automatically in the library using the
                                            <code class="code">mbstring</code> module in PHP. Note that the
                                        multibyte extension in PHP is not normally enabled.</td></tr></tbody></table>
                    </div></div><p><br class="table-break">
                </p>
                <p>Otherwise it is assumed that the input characters are encoded in UTF-8.
                    Remember that to show the Japanese character sets (Kanji, Hiragana and Katakana)
                    one of the Japanese font families (<code class="code">FF_MINCHO</code>,
                        <code class="code">FF_PMINCHO</code>, <code class="code">FF_GOTHIC</code> or <code class="code">FF_PGOTHIC</code>)
                    must be specified. </p>
                <p>An example of using Japanese locale together with Windrose plots can be seen
                    in <a class="xref" href="ch21s03.html#sec.windrose-locale-compass" title="Localizing the default names for the compass directions">Localizing the default names for the compass directions</a>.</p>
            </div>
            <div class="sect2" title="Chinese encoding options"><div class="titlepage"><div><div><h3 class="title"><a name="id2500408"></a>Chinese encoding options</h3></div></div></div>
                
                <p>There are no specific settings that control the encoding. The following rules
                    are used depending on the font is specified. </p>
                <p>
                    </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
                            <p>If the font is specified as <code class="code">FF_SIMSUN</code> the built-in
                                library conversion from GB2312 to UTF-8 will be used. This
                                translation table is stored in the file
                                    <code class="filename">jpgraph_gb2312.inc.php</code>.</p>
                        </li><li class="listitem">
                            <p>If the font is specified as <code class="code">FF_CHINESE</code> then no
                                conversion is made since it is assumed that the input character
                                string is already in UTF-8 This only has the effect of changing the
                                font to the default Chinese font family.</p>
                        </li><li class="listitem">
                            <p>If the font is specified as <code class="code">FF_BIG5</code> then it is
                                assumed that the input character string is encoded in BIG5 and the
                                internal translation to UTF-8 is done by the <code class="code">iconv()</code>
                                function. This means that PHP must be built with
                                    <code class="code">iconv()</code> support. By default this is not compiled
                                into PHP (needs the "<code class="code">--width-iconv</code>" when configured).
                                For more on building PHP with the right options see <a class="xref" href="api.html" title="Appendix I. Compiling PHP">Appendix I. <i>Compiling PHP</i></a>. If this method is not present
                                the library will generate the following an error message.</p>
                        </li></ol></div><p>
                </p>
                <p>An example of using Chinese encoding with Windrose plots can be seen in <a class="xref" href="ch21s03.html#fig.windrose_ex6.1" title="Figure 21.11. Using chinese fonts (windrose_ex6.1.php)">Figure 21.11. Using chinese fonts <code class="uri"><a class="uri" href="example_src/windrose_ex6.1.html" target="_top">(<code class="filename">windrose_ex6.1.php</code>)</a></code> </a>
                </p>
            </div>
            <div class="sect2" title="Cyrillic encoding options"><div class="titlepage"><div><div><h3 class="title"><a name="id2500502"></a>Cyrillic encoding options</h3></div></div></div>
                
                <p>In order to do proper translation to unicode from cyrillic the
                        <code class="code">LANGUAGE_CYRILLIC</code> define should be set to true. If you are
                    running the library in multiuser environment it might be necessary to also
                    adjust the <code class="code">LANGUGAE_CHARSET</code> define as described below.</p>
                <p>
                    </p><div class="table"><a name="id2500523"></a><p class="title"><b>Table 8.5. Cyrillic encoding options</b></p><div class="table-contents">
                        
                        <table summary="Cyrillic encoding options" border="1"><colgroup><col class="c1"><col class="c2"><col class="c3"></colgroup><thead><tr><th>Symbolic define</th><th>Possible values </th><th>Description</th></tr></thead><tbody><tr><td><code class="code">LANGUAGE_CYRILLIC</code></td><td>true/false</td><td>
                                        <p>Special unicode cyrillic language support</p>
                                    </td></tr><tr><td><code class="code">CYRILLIC_FROM_WINDOWS</code></td><td>true/false</td><td>
                                        <p>If you are setting this config to true the conversion
                                            will assume that the input text is encoded in windows
                                            1251, if false it will assume koi8-r</p>
                                    </td></tr><tr><td><code class="code">LANGUAGE_CHARSET</code></td><td>string</td><td>
                                        <p>This constant is used to auto-detect whether cyrillic
                                            conversion is really necessary if enabled. Just specify
                                            the encoding used, e.g. 'windows-1251', with a variable
                                            containing the input character encoding string of your
                                            application calling JpGraph. </p>
                                        <p>A typical such string would be 'UTF-8' or 'utf-8'. The
                                            comparison is case-insensitive. If this charset is not a
                                            'koi8-r' or 'windows-1251' derivate then no conversion
                                            is done. This constant can be very important in
                                            multi-user multi-language environments where a cyrillic
                                            conversion could be needed for some cyrillic people and
                                            resulting in just erroneous conversions for non cyrillic
                                            language based people. </p>
                                        <p>Example: In the free project management software
                                            dotproject.net <code class="code">$locale_char_set</code> is
                                            dynamically set by the language environment the user has
                                            chosen. </p>
                                        <p>Usage: <code class="code">define('LANGUAGE_CHARSET',
                                                $locale_char_set);</code> where
                                                <code class="code">$locale_char_set</code> is a GLOBAL (string)
                                            variable from the application including JpGraph.</p>
                                    </td></tr></tbody></table>
                    </div></div><p><br class="table-break">
                </p>
            </div>
            <div class="sect2" title="Hebrew encoding options"><div class="titlepage"><div><div><h3 class="title"><a name="id2500687"></a>Hebrew encoding options</h3></div></div></div>
                
                <p>There are no user adjustable settings. The conversion is made from iso to
                    unicode with the help of the PHP method "<code class="code">hebrev()</code>" which is used to
                    convert logical Hebrew text to visual text. This conversion is done
                    automatically when the font is one of <code class="code">FF_DAVID</code>,
                        <code class="code">FF_MIRIAM</code> or <code class="code">FF_AHRON</code></p>
            </div>
            <div class="sect2" title="Greek encoding options"><div class="titlepage"><div><div><h3 class="title"><a name="id2500718"></a>Greek encoding options</h3></div></div></div>
                
                <p>In order to do proper translation to unicode from greek the
                        <code class="code">LANGUAGE_GREEK</code> define should be specified to true.</p>
                <p>
                    </p><div class="table"><a name="id2500733"></a><p class="title"><b>Table 8.6. Greek encoding options</b></p><div class="table-contents">
                        
                        <table summary="Greek encoding options" border="1"><colgroup><col class="c1"><col class="c2"><col class="c3"></colgroup><thead><tr><th>Symbolic define</th><th>Possible values </th><th>Description</th></tr></thead><tbody><tr><td><code class="code">LANGUAGE_GREEK</code></td><td>true/false</td><td>Special unicode greek language support</td></tr><tr><td><code class="code">GREEK_FROM_WINDOWS</code></td><td>true/false</td><td>If you are setting this define to true the conversion of
                                        greek characters will assume that the input text is windows
                                        1251</td></tr></tbody></table>
                    </div></div><p><br class="table-break">
                </p>
            </div>
        </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch08.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
